package com.javastudy.thread;

public class VolatileTest {
    private static int init_value = 0;

    public static void main(String[] args) {
        new Thread(() -> {
            int a = init_value;
            while (a < 500){
                if(a != init_value){
                    System.out.printf("the value is update to [%d]\n", init_value);
                    a = init_value;
                }
            }
        }, "read").start();

        new Thread(() -> {
           int a = init_value;
           while (a < 500){
               System.out.printf("the value is change to [%d]\n", a++);
               init_value = a;
           }
        }, "update").start();
    }
}
